var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var i in t) t.hasOwnProperty(i) && (e[i] = t[i]);
    })(e, t);
}, function(e, t) {
    function i() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (i.prototype = t.prototype, 
    new i());
}), a = this && this.__decorate || function(e, t, i, o) {
    var n, r = arguments.length, s = r < 3 ? t : null === o ? o = Object.getOwnPropertyDescriptor(t, i) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, i, o); else for (var a = e.length - 1; 0 <= a; a--) (n = e[a]) && (s = (r < 3 ? n(s) : 3 < r ? n(t, i, s) : n(t, i)) || s);
    return 3 < r && s && Object.defineProperty(t, i, s), s;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("EditView"), s = e("GameManager"), c = e("Global"), l = e("GameConfig"), d = e("GameData"), u = e("ActivityManager"), p = e("PlayerModel"), h = e("AudioManager"), f = cc._decorator, g = f.ccclass, m = (f.property, 
function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.url = "", e.gameView = null, e.sprite = null, e.gird = null, e.type = 0, 
        e.HP = 50, e.targetList = [], e.prefab = null, e.isDestory = !1, e.isAnimation = !1, 
        e.isUpdate = !1, e;
    }
    return i(e, t), e.prototype.onLoad = function() {
        this.gameView || (this.gameView = s.default.getInstance().gameView);
    }, e.prototype.init = function(e) {
        var n = this;
        return new Promise(function(t, i) {
            var o;
            e ? (o = s.default.getInstance().gameView) ? o.appendSprite({
                url: e,
                root: n.node.parent,
                pos: cc.v2(n.node.x, n.node.y - 40)
            }).then(function(e) {
                try {
                    n.sprite = e, n.sprite.node.zIndex = n.node.zIndex, n.sprite.node.angle = 0, n.sprite.node.anchorY = 0, 
                    n.type == r.BlockType.GRASS ? o.getPrefab("prefab/animation/" + n.name).then(function(e) {
                        n.prefab = e, t();
                    }) : t();
                } catch (e) {
                    i();
                }
            }, function() {
                i();
            }) : i() : t();
        });
    }, e.prototype.isCanBlock = function(e) {
        return this.type == r.BlockType.BLOCK ? e != p.ArmType.科技枪 : this.type == r.BlockType.BOX && e != p.ArmType.狙击枪 && e != p.ArmType.激光枪;
    }, e.prototype.isCanAttacked = function(e) {
        return this.type == r.BlockType.BOX || this.type == r.BlockType.GRASS && (e == p.ArmType.暴力枪 || e == p.ArmType.导弹枪);
    }, e.prototype.doHurt = function(e) {
        try {
            var t = Math.floor((1 + (Math.random() - .5) / 10) * e.ATK), i = e.isCri(e.CRI), o = s.default.getInstance().gameView;
            if (o && o.appendCri(e.type, this.node.getPosition(), t, i), i ? this.hurt(2 * t) : this.hurt(t)) return this.doEffect(), 
            this.doDestroy(), !0;
        } catch (e) {
            return cc.error(e), !1;
        }
        return !1;
    }, e.prototype.hurt = function(e) {
        return this.HP > e ? (this.HP -= e, !1) : !(this.HP = 0);
    }, e.prototype.doEffect = function() {
        var e, i;
        this.type == r.BlockType.BOX && (this.gameView || (this.gameView = s.default.getInstance().gameView), 
        this.gameView) && (e = this.node.position, i = this.node.zIndex, this.gameView.appendSkeleton({
            url: "skeleton/game/hurt0/skeleton",
            root: this.node.parent,
            pos: cc.v2(e)
        }).then(function(e) {
            var t;
            e && (e.node.zIndex = i, e.node.active = !0, t = GA.rand(1, 4), e.setAnimation(0, "animation" + t, !1), 
            e.setCompleteListener(function() {
                s.default.getInstance().gameView.removeSkeleton(e.node);
            }));
        }));
    }, e.prototype.doDestroy = function() {
        var e, t;
        this.isDestory || (this.isDestory = !0, this.gameView || (this.gameView = s.default.getInstance().gameView), 
        this.gameView && (-1 == this.gameView.astar.gridsList[this.gird.x][this.gird.y].type && (this.gameView.astar.gridsList[this.gird.x][this.gird.y].type = 0), 
        this.gameView.astar.gridsList[this.gird.x][this.gird.y].target = null, this.gameView.blocks.splice(this.gameView.blocks.indexOf(this), 1), 
        this.sprite && this.sprite.node.destroy(), d.GD.isVibrate && (null === (t = null === (e = GA.PA) || void 0 === e ? void 0 : e.vibrateShort) || void 0 === t || t.call(e, {})), 
        u.ActivityManager.getInstance().checkActivity(u.ActivityType.NEWYEAR) && c.G.newYearDropCount < c.G.newYearDropTotal && Math.random() < l.GC.newYearDropScale && (c.G.newYearDropCount++, 
        this.addBox(this.gird)), this.node.destroy()));
    }, e.prototype.doUpdate = function(i) {
        var o, n = this;
        this.type == r.BlockType.GRASS && (o = this.node.getBoundingBox(), this.sprite.node.opacity = 255, 
        s.default.getInstance().gameView.targets.forEach(function(e) {
            var t = n.targetList.indexOf(e);
            e && e.checkTarget(e) ? (e.node.x >= o.xMin && e.node.x <= o.xMax && e.node.y >= o.yMin && e.node.y <= o.yMax ? (e.model.hasBuffer(p.BufferType.隐藏中) || e.model.addBuffer(p.BufferType.暴露中, 3), 
            e.model.addBuffer(p.BufferType.隐藏中, 5 * i), t < 0 && (n.targetList.push(e), n.doAnimation(e))) : -1 < t && n.targetList.splice(t, 1), 
            e.model.group == n.gameView.curPlayer.model.group && e.checkVisual(n.node.getPosition()) && (n.sprite.node.opacity = 150)) : -1 < t && n.targetList.splice(t, 1);
        }), 255 == this.sprite.node.opacity && (this.isUpdate = !1));
    }, e.prototype.doAnimation = function(e) {
        var t, i = this;
        !this.isDestory && !this.isAnimation && this.prefab && this.sprite && (e.model.openid == GA.Info.openId && h.default.getInstance().playAudio("战斗草"), 
        this.isAnimation = !0, this.sprite && (this.sprite.enabled = !1), (t = cc.instantiate(this.prefab)).setParent(this.sprite.node), 
        t.setPosition(cc.v2(-2, 65)), (e = t.getComponent(cc.Animation)) && (e.on("finished", function() {
            t.destroy(), i.sprite && (i.sprite.enabled = !0), i.isAnimation = !1;
        }), e.play()));
    }, e.prototype.addBox = function(e) {
        var t = new cc.Node(), i = t.addComponent("GameBlockNewYear");
        i && (t.parent = this.gameView.layout, i.gird = e, t.setContentSize(80, 80), t.zIndex = 2 * -e.y, 
        t.setPosition(cc.v2(80 * i.gird.x + 40 - this.gameView.map.width / 2, 80 * i.gird.y + 40 - this.gameView.map.height / 2)), 
        i.type = r.BlockType.BOX, i.init("texture/map/christmas/egg_0"), this.gameView.blocks.push(i), 
        this.gameView.astar.gridsList[e.x][e.y].type = -1, this.gameView.astar.gridsList[e.x][e.y].target = i);
    }, a([ g ], e);
}(cc.Component));

n.default = m;